package com.jhgsys.internal.incentive.service.impl;

import com.jhgsys.internal.incentive.entity.IncentiveQuotaAuditRecord;
import com.jhgsys.internal.incentive.mapper.IncentiveQuotaAuditRecordMapper;
import com.jhgsys.internal.incentive.service.IIncentiveQuotaAuditRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *  Service实现
 *
 * @author zhangwei
 * @date 2024-09-04 13:56:17
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class IncentiveQuotaAuditRecordServiceImpl extends ServiceImpl<IncentiveQuotaAuditRecordMapper, IncentiveQuotaAuditRecord> implements IIncentiveQuotaAuditRecordService {

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     * @param request QueryRequest
     * @param incentiveQuotaAuditRecord incentiveQuotaAuditRecord
     * @return IPage<IncentiveQuotaAuditRecord>
    */
    @Override
    public IPage<IncentiveQuotaAuditRecord> findIncentiveQuotaAuditRecordPage(QueryRequest request, IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
        LambdaQueryWrapper<IncentiveQuotaAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveQuotaAuditRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<IncentiveQuotaAuditRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     * @param incentiveQuotaAuditRecord incentiveQuotaAuditRecord
     * @return List<IncentiveQuotaAuditRecord>
     */
    @Override
    public List<IncentiveQuotaAuditRecord> findIncentiveQuotaAuditRecordList(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
	    LambdaQueryWrapper<IncentiveQuotaAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveQuotaAuditRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zhangwei
    * @date 2024-09-04 13:56:17
    * @param id
    * @return IncentiveQuotaAuditRecord
    */
    @Override
    public IncentiveQuotaAuditRecord findIncentiveQuotaAuditRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     * @param incentiveQuotaAuditRecord incentiveQuotaAuditRecord
     */
    @Override
    @Transactional
    public void createIncentiveQuotaAuditRecord(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
        incentiveQuotaAuditRecord.setCreatedTime(new Date());
        this.save(incentiveQuotaAuditRecord);
    }

    /**
     * 修改
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     * @param incentiveQuotaAuditRecord incentiveQuotaAuditRecord
     */
    @Override
    @Transactional
    public void updateIncentiveQuotaAuditRecord(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord) {
        incentiveQuotaAuditRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(incentiveQuotaAuditRecord);
    }

    /**
     * 逻辑删除
     * @author zhangwei
     * @date 2024-09-04 13:56:17
     * @param incentiveQuotaAuditRecord incentiveQuotaAuditRecord
     * @param incentiveQuotaAuditRecordIds incentiveQuotaAuditRecordIds
     */
    @Override
    @Transactional
    public void deleteIncentiveQuotaAuditRecord(IncentiveQuotaAuditRecord incentiveQuotaAuditRecord,String incentiveQuotaAuditRecordIds) {
        List<String> list = Arrays.asList(incentiveQuotaAuditRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(incentiveQuotaAuditRecord,new LambdaQueryWrapper<IncentiveQuotaAuditRecord>().in(IncentiveQuotaAuditRecord::getQuotaAuditRecordId,list));
	}

    /**
    * 物理删除
    * @author zhangwei
    * @date 2024-09-04 13:56:17
    * @param incentiveQuotaAuditRecordIds incentiveQuotaAuditRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteIncentiveQuotaAuditRecord(String incentiveQuotaAuditRecordIds) {
        List<String> list = Arrays.asList(incentiveQuotaAuditRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<IncentiveQuotaAuditRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(IncentiveQuotaAuditRecord::getQuotaAuditRecordId,list);
        this.remove(wapper);
    }
}
